package file.listener;

import file.FileFrame;

import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

/**
 * 为搜索框增加焦点
 * @Author: zou
 * @email: 704572528@qq.com
 * @Date: 2020/10/31 15:16
 */
public class SearchNameFocus extends FileFrameAbstract implements FocusListener {

    private final static String focusName = "搜素我的文件";

    public SearchNameFocus(FileFrame fileFrame) {
        super(fileFrame);
    }


    /**
     * 焦点获取
     * @param e
     */
    @Override
    public void focusGained(FocusEvent e) {
        JTextArea sn = fileFrame.getSearchName();
        String tempString = sn.getText();
        //String tempString = this.getText();
       /* if (tempString.equals(focusName)){
            sn.setText("");
            sn.setForeground(Color.BLACK);
        }*/
    }

    /**
     * 焦点失去
     * @param e
     */
    @Override
    public void focusLost(FocusEvent e) {
        JTextArea sn = fileFrame.getSearchName();
        String tempString = sn.getText();
        if(tempString.equals("")) {
            sn.setForeground(Color.GRAY);
            sn.setText(focusName);
        }
    }

}
